home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 6.7 KB | 165 lines |
- '****************************************************************************
- ' Simple ~Walk Around The Maze~ Routine By Steve Bennett
- ' From an idea by Jason Holborn
- '****************************************************************************
- '
- ' If you are new to AMOS, you may not have fully understood the routine
- ' that Jason explained in ~Amiga Shopper~.
- ' Below is a small ~Bare Bones~ routine to give you some idea what he meant.
- ' I have kept it as simple as I can. It is up to you to change the code as
- ' you wish. The first thing to do is to add a few lines of code so that the
- ' Pacman Bob doesn't move 16 pixels at a time.
- ' Take your time, you can do it.
- '
- ' Remove the ~Rems~ and see how small the code really is!
- '****************************************************************************
- '
- ' I have just written this code and have found that by drawing the maze in
- ' the way I have (Left To Right) means that when you want to check a square
- ' on the grid, instead of checking -
- ' X Right Then Y Down
- '
- ' EXAMPLE: CHECK_VALID_MOVE(X,Y)
- '
- ' You must do it the other way around -
- ' Y Down Then X Right
- '
- ' EXAMPLE: CHECK_VALID_MOVE(Y,X)
- '
- ' Its not my mistake, I wrote the code just to draw a maze, Jason saw the
- ' true potential of this routine and this method of moving around a maze.
- '
- ' It should be no real problem for you to change the code so that the icons
- ' are pasted from (Top To Bottom) it you want, then the check will be the
- ' correct way around!
- '
- '****************************************************************************
-
- PACMANX=2 : Rem * used to store the pacmans X position on grid *
- PACMANY=2 : Rem * used to store the pacmans Y position on grid *
-
- Dim CHECK_VALID_MOVE(14,18) : Rem * stores the value of each grid square *
-
- Hide On : Rem * hide the mouse *
-
- Screen Open 0,320,256,32,Lowres
- Get Icon Palette
- Flash Off : Curs Off
- Cls 0
-
- CREATE_MAZE : Rem * go and create a maze *
-
- Double Buffer : Rem * use Double Buffer to stop Bob flicker *
-
- Bob 1,31,35,1 : Rem * place the pacman Bob on the screen *
-
- Repeat : Rem * start of the main game loop *
-
- CHECK_STICK : Rem * check if the joystick is being moved *
-
- Wait 5 : Rem * slow the bob movement down a bit *
-
- Until Mouse Key=1 : Rem * REPEAT - UNTIL we click the left mouse button *
-
- Procedure CHECK_STICK
-
- '****************************************************************************
- ' This bit may look hard, but all it does is test which way the joystick is
- ' held then adds or subracts 1 To/From the values of the Bobs Grid Position -
- ' These are held in the PACMANX & PACMANY variables.
- '
- ' PACMANX - holds the Bobs X position on the grid.
- ' PACMANY - holds the Bobs Y position on the grid.
- '
- ' It then checks if the Grid Square in front of the Bob (This depends which
- ' way the Bob is moving). If the value of that Square is 2 then that means
- ' the next Grid Square is a wall so we stop the Bob moving onto it.
- '
- ' If the next Grid Square is not a wall, then we move the Bob onto it.
- '
- ' READ THE MAZE_CRAZY DOCS FILE ON THE DISK AND I'LL TRY TO EXPLAIN IT A
- ' BIT BETTER FOR YOU.
- '****************************************************************************
-
- Shared CHECK_VALID_MOVE(),PACMANX,PACMANY
-
- J=Joy(1) : Rem * test which direction the joystick is held *
-
- If J=1 : Rem * is it up? *
- If CHECK_VALID_MOVE(PACMANY-1,PACMANX)<>2
- Dec PACMANY
- Bob 1,,Y Bob(1)-16,12 : Rem * move the Bob down the screen *
- End If
- End If
-
- If J=2 : Rem * is it down *
- If CHECK_VALID_MOVE(PACMANY+1,PACMANX)<>2
- Inc PACMANY
- Bob 1,,Y Bob(1)+16,13 : Rem * move the Bob up the screen *
- End If
- End If
-
- If J=4 : Rem * is it left *
- If CHECK_VALID_MOVE(PACMANY,PACMANX-1)<>2
- Dec PACMANX
- Bob 1,X Bob(1)-16,,8 : Rem * move the Bob left *
- End If
- End If
-
- If J=8 : Rem * is it right *
- If CHECK_VALID_MOVE(PACMANY,PACMANX+1)<>2
- Inc PACMANX
- Bob 1,X Bob(1)+16,,1 : Rem * move the Bob right *
- End If
- End If
-
- '****************************************************************************
- ' You could put your ~Eat Pills~ routine here if you wanted to.
- ' It would best to do this when you move the Bob though, to avoid clearing
- ' the same area over & over, as the code here does.
- ' These next few lines just use the Cls just to so you the sort of effect.
- '****************************************************************************
-
- X=X Bob(1) : Y=Y Bob(1)
- Cls 0,X,Y To X+16,Y+16
-
- End Proc
- Procedure CREATE_MAZE
-
- Shared CHECK_VALID_MOVE()
-
- STORE_DATA=1
-
- Y=20 : Rem * ~Y~ start position of the first icon to paste down *
-
- For T=1 To 14 : Rem * loop to paste the icon across the screen *
- For X=15 To 294 Step 16 : Rem * how many pixels apart to paste the icons *
- Read I : Rem * read the next data value *
- CHECK_VALID_MOVE(T,STORE_DATA)=I
- If I<>0 Then Paste Icon X,Y,I : Rem * paste down icon ~I~ *
- Inc STORE_DATA
- Next X
- Add Y,16 : Rem * after line is complete across - drop down to the next line *
- STORE_DATA=1
- Next T
-
- '****************************************************************************
- ' Data for the Maze itself - 2=Wall - 3=Pill - 0=Empty space
- '****************************************************************************
-
- Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
- Data 2,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,2
- Data 2,2,3,2,3,2,3,2,3,2,3,2,2,3,2,0,0,2
- Data 2,2,3,2,3,2,3,2,3,2,3,2,2,3,2,2,2,2
- Data 2,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,2
- Data 2,2,2,3,2,2,2,2,3,2,3,2,2,2,2,2,3,2
- Data 2,3,3,3,3,3,3,3,3,2,3,3,3,3,2,2,3,2
- Data 2,2,3,2,3,2,2,3,2,2,2,2,2,3,3,3,3,2
- Data 2,3,3,3,3,2,2,3,3,3,3,3,2,3,2,2,3,2
- Data 2,2,3,2,3,2,2,3,2,2,2,3,2,3,3,3,3,2
- Data 2,3,3,2,3,3,3,3,2,3,2,3,3,3,2,3,2,2
- Data 2,3,2,2,3,2,2,3,2,3,2,3,2,3,2,2,3,2
- Data 2,3,3,2,3,2,2,3,3,3,2,3,2,3,3,3,3,2
- Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
-
- End Proc